jQuery.extend({
    sumTableBlock: function (begin, end, table) {
        var sum = 0;
        for (var i = begin; i <= end; i++) {
            sum += Number(table[i].innerText);
        }

        console.log(sum)
        return sum;
    },

    mainTableCSS: function(){
        var mainTableContent = $("#MainTable table").children().children();
        for (var i = 1; i < mainTableContent.length; i++) {
            var tdNodes = mainTableContent[i].children;
            tdNodes[2].className += " right_blod";

            for (var j = 3; j < tdNodes.length; j++) {
                if (Number(tdNodes[j].innerText) == -1) {
                    tdNodes[j].innerHTML = "&nbsp;";
                }

                if (j == 10 || j == 18 || j == 19 || j == 27 || j == 35) {
                    tdNodes[j].className += " right_blod";
                }
            }


            for (var j = 14; j <= 24; j++) {
                tdNodes[j].className += " pink_bg";
            }

            if ($.sumTableBlock(3, 10, tdNodes) == 0) {
                for (var j = 3; j <= 10; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(11, 18, tdNodes) == 0) {
                for (var j = 11; j <= 18; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(20, 27, tdNodes) == 0) {
                for (var j = 20; j <= 27; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(28, 35, tdNodes) == 0) {

                for (var j = 28; j <= 35; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }
        }
    },
    
    eightDigitTableCSS: function(){
        var eightDigitTableContent = $("#EightDigitTable table").children().children();
        for (var i = 1; i < eightDigitTableContent.length; i++) {
            var tdNodes = eightDigitTableContent[i].children;

            tdNodes[1].className += " right_blod";


            for (var j = 2; j < tdNodes.length; j++) {
                if (Number(tdNodes[j].innerText) == -1) {
                    tdNodes[j].innerHTML = "&nbsp;";
                }

                if (j == 5 || j == 9 || j == 13 || j == 17 || j == 21 || j == 25 || j == 29 || j == 33 || j == 34) {
                    tdNodes[j].className += " right_blod";
                }
            }

            if ($.sumTableBlock(2, 5, tdNodes) == 0) {
                for (var j = 2; j <= 5; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(6, 9, tdNodes) == 0) {
                for (var j = 6; j <= 9; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(10, 13, tdNodes) == 0) {
                for (var j = 10; j <= 13; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(14, 17, tdNodes) == 0) {
                for (var j = 14; j <= 17; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(18, 21, tdNodes) == 0) {
                for (var j = 18; j <= 21; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(22, 25, tdNodes) == 0) {
                for (var j = 22; j <= 25; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(26, 29, tdNodes) == 0) {
                for (var j = 26; j <= 29; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(30, 33, tdNodes) <= 0) {
                for (var j = 30; j <= 33; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }
        }
    },
    
    elevenDigitTableCSS: function(){
        var elevenDigitTableContent = $("#ElevenDigitTable table").children().children();
        for (var i = 1; i < elevenDigitTableContent.length; i++) {
            var tdNodes = elevenDigitTableContent[i].children;

            tdNodes[0].className += "right_blod";


            for (var j = 1; j < tdNodes.length; j++) {
                if (Number(tdNodes[j].innerText) == -1) {
                    tdNodes[j].innerHTML = "&nbsp;";
                }

                if (j == 3 || j == 6 || j == 9 || j == 12 || j == 15 || j == 18 || j == 21 || j == 24 || j == 27 || j == 30 || j == 33 || j == 37 || j == 40 || j == 44 || j == 47 || j == 51 || j == 55) {
                    tdNodes[j].className += " right_blod";
                }
            }

            for (var t = 1; t <= 11; t++) {
                var index = t * 3 - 2;
                if ($.sumTableBlock(index, index + 2, tdNodes) == 0) {
                    for (var j = index; j <= index + 2; j++) {
                        tdNodes[j].className += " blue_bg";
                    }
                }
            }

            if ($.sumTableBlock(34, 37, tdNodes) == 0) {
                for (var j = 34; j <= 37; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(38, 40, tdNodes) == 0) {
                for (var j = 38; j <= 40; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(41, 44, tdNodes) == 0) {
                for (var j = 41; j <= 44; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(45, 47, tdNodes) == 0) {
                for (var j = 45; j <= 47; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(48, 51, tdNodes) == 0) {
                for (var j = 48; j <= 51; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(52, 55, tdNodes) == 0) {
                for (var j = 52; j <= 55; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }
        }
    },
    
    blueTableCSS: function() {
        var blueTableContent = $("#BlueTable table").children().children();
        for (var i = 1; i < blueTableContent.length; i++) {
            var tdNodes = blueTableContent[i].children;

            tdNodes[0].className += "right_blod";


            for (var j = 1; j < tdNodes.length; j++) {
                if (Number(tdNodes[j].innerText) == -1) {
                    tdNodes[j].innerHTML = "&nbsp;";
                } else if ((j > 0 && j < 17) || (j > 29 && j < 34)) {
                    tdNodes[j].className += " blue_bg"
                } else if ((j > 16 && j < 25) || (j > 35 && j < 39)) {
                    tdNodes[j].className += " red_bg"
                }

                if (j == 4 || j == 8 || j == 12 || j == 16 || j == 24 || j == 27 || j == 29 || j == 33 || j == 35 || j == 38 || j == 42) {
                    tdNodes[j].className += " right_blod";
                }
            }
        }
    },
    evenTableCSS: function(){
        var evenTableContent = $("#EvenTable table").children().children();
        for (var i = 1; i < evenTableContent.length; i++) {
            var tdNodes = evenTableContent[i].children;

            tdNodes[2].className += "right_blod";


            for (var j = 3; j < tdNodes.length; j++) {
                if (Number(tdNodes[j].innerText) == -1) {
                    tdNodes[j].innerHTML = "&nbsp;";
                }

                if (j == 10 || j == 18 || j == 22 || j == 30 || j == 34) {
                    tdNodes[j].className += " right_blod";
                }
            }

            if ($.sumTableBlock(3, 6, tdNodes) == 0) {
                for (var j = 3; j <= 6; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(7, 10, tdNodes) == 0) {
                for (var j = 7; j <= 10; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(11, 14, tdNodes) == 0) {
                for (var j = 11; j <= 14; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(15, 18, tdNodes) == 0) {
                for (var j = 15; j <= 18; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(19, 22, tdNodes) == 0) {
                for (var j = 19; j <= 22; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(23, 26, tdNodes) == 0) {
                for (var j = 23; j <= 26; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(27, 30, tdNodes) == 0) {
                for (var j = 27; j <= 30; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(31, 34, tdNodes) == 0) {
                for (var j = 31; j <= 34; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }
        }
    },
    oddTableCSS: function(){
        var oddTableContent = $("#OddTable table").children().children();
        for (var i = 1; i < oddTableContent.length; i++) {
            var tdNodes = oddTableContent[i].children;

            tdNodes[2].className += "right_blod";


            for (var j = 3; j < tdNodes.length; j++) {
                if (Number(tdNodes[j].innerText) == -1) {
                    tdNodes[j].innerHTML = "&nbsp;";
                }

                if (j == 10 || j == 11 || j == 19 || j == 23 || j == 31 || j == 35) {
                    tdNodes[j].className += " right_blod";
                }
            }

            if ($.sumTableBlock(3, 6, tdNodes) == 0) {
                for (var j = 3; j <= 6; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(7, 10, tdNodes) == 0) {
                for (var j = 7; j <= 10; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(12, 15, tdNodes) == 0) {
                for (var j = 12; j <= 15; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(16, 19, tdNodes) == 0) {
                for (var j = 16; j <= 19; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(20, 23, tdNodes) == 0) {
                for (var j = 20; j <= 23; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(24, 27, tdNodes) == 0) {
                for (var j = 24; j <= 27; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(28, 31, tdNodes) == 0) {
                for (var j = 28; j <= 31; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(32, 35, tdNodes) == 0) {
                for (var j = 32; j <= 35; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

        }
    },
    
    fourPart012TableCSS: function() {
        var fourPart012TableContent = $("#FourPart012Table table").children().children();
        for (var i = 1; i < fourPart012TableContent.length; i++) {
            var tdNodes = fourPart012TableContent[i].children;

            tdNodes[1].className += "right_blod";

            for (var j = 2; j < tdNodes.length; j++) {
                if (Number(tdNodes[j].innerText) == -1) {
                    tdNodes[j].innerHTML = "&nbsp;";
                }

                if (j == 3 || j == 6 || j == 9 || j == 12 || j == 15 || j == 18 || j == 21 || j == 24 || j == 26 || j == 29 || j == 31 || j == 34) {
                    tdNodes[j].className += " right_blod";
                }
            }

            if ($.sumTableBlock(2, 3, tdNodes) == 0) {
                for (var j = 2; j <= 3; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(4, 6, tdNodes) == 0) {
                for (var j = 4; j <= 6; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(7, 9, tdNodes) == 0) {
                for (var j = 7; j <= 9; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(10, 12, tdNodes) == 0) {
                for (var j = 10; j <= 12; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(13, 15, tdNodes) == 0) {
                for (var j = 13; j <= 15; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(16, 18, tdNodes) == 0) {
                for (var j = 16; j <= 18; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(19, 21, tdNodes) == 0) {
                for (var j = 19; j <= 21; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(22, 24, tdNodes) == 0) {
                for (var j = 22; j <= 24; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(25, 26, tdNodes) == 0) {
                for (var j = 25; j <= 26; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(27, 29, tdNodes) == 0) {
                for (var j = 27; j <= 29; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(30, 31, tdNodes) == 0) {
                for (var j = 30; j <= 31; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(32, 34, tdNodes) == 0) {
                for (var j = 32; j <= 34; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }
        }
    },
    
     fourPartEnd012TableCSS: function(){
        var fourPartEnd012TableContent = $("#FourPartEnd012Table table").children().children();
        for (var i = 1; i < fourPartEnd012TableContent.length; i++) {
            var tdNodes = fourPartEnd012TableContent[i].children;

            tdNodes[1].className += "right_blod";

            for (var j = 2; j < tdNodes.length; j++) {
                if (Number(tdNodes[j].innerText) == -1) {
                    tdNodes[j].innerHTML = "&nbsp;";
                }

                if (j == 3 || j == 6 || j == 9 || j == 12 || j == 15 || j == 16 || j == 18 || j == 20 || j == 23 || j == 26 || j == 29 || j == 32 || j == 34) {
                    tdNodes[j].className += " right_blod";
                }
            }

            if ($.sumTableBlock(2, 3, tdNodes) == 0) {
                for (var j = 2; j <= 3; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(4, 6, tdNodes) == 0) {
                for (var j = 4; j <= 6; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(7, 9, tdNodes) == 0) {
                for (var j = 7; j <= 9; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(10, 12, tdNodes) == 0) {
                for (var j = 10; j <= 12; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(13, 15, tdNodes) == 0) {
                for (var j = 13; j <= 15; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(17, 18, tdNodes) == 0) {
                for (var j = 16; j <= 18; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(19, 20, tdNodes) == 0) {
                for (var j = 19; j <= 20; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(21, 23, tdNodes) == 0) {
                for (var j = 21; j <= 23; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(24, 26, tdNodes) == 0) {
                for (var j = 24; j <= 26; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(27, 29, tdNodes) == 0) {
                for (var j = 27; j <= 29; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(30, 32, tdNodes) == 0) {
                for (var j = 30; j <= 32; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(33, 34, tdNodes) == 0) {
                for (var j = 33; j <= 34; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }
        }
    },

     end3dTableCSS: function(){
        var end3dTableContent = $("#End3dTable table").children().children();
        for (var i = 1; i < end3dTableContent.length; i++) {
            var tdNodes = end3dTableContent[i].children;

            tdNodes[0].className += "right_blod";

            for (var j = 1; j < tdNodes.length; j++) {
                if (Number(tdNodes[j].innerText) == -1) {
                    tdNodes[j].innerHTML = "&nbsp;";
                }

                if (j == 6 || j == 12 || j == 15 || j == 21 || j == 24 || j == 27 || j == 31 || j == 35 || j == 39 || j == 44 || j == 47 || j == 50 || j == 54) {
                    tdNodes[j].className += " right_blod";
                }
            }


            if ($.sumTableBlock(22, 24, tdNodes) == 0) {
                for (var j = 22; j <= 24; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(25, 27, tdNodes) == 0) {
                for (var j = 25; j <= 27; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(28, 31, tdNodes) == 0) {
                for (var j = 28; j <= 31; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(32, 35, tdNodes) == 0) {
                for (var j = 32; j <= 35; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(36, 39, tdNodes) == 0) {
                for (var j = 36; j <= 39; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(40, 44, tdNodes) == 0) {
                for (var j = 40; j <= 44; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(45, 47, tdNodes) == 0) {
                for (var j = 45; j <= 47; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(48, 50, tdNodes) == 0) {
                for (var j = 48; j <= 50; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(51, 54, tdNodes) == 0) {
                for (var j = 51; j <= 54; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }
        }
    },

     endTableCSS: function() {
        var endTableContent = $("#EndTable table").children().children();
        for (var i = 1; i < endTableContent.length; i++) {
            var tdNodes = endTableContent[i].children;

            tdNodes[1].className += "right_blod";

            for (var j = 2; j < tdNodes.length; j++) {
                if (Number(tdNodes[j].innerText) == -1) {
                    tdNodes[j].innerHTML = "&nbsp;";
                }

                if (j == 5 || j == 9 || j == 13 || j == 16 || j == 19 || j == 22 || j == 25 || j == 28 || j == 31 || j == 34) {
                    tdNodes[j].className += " right_blod";
                }
            }

            if ($.sumTableBlock(2, 5, tdNodes) == 0) {
                for (var j = 2; j <= 5; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(6, 9, tdNodes) == 0) {
                for (var j = 6; j <= 9; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(10, 13, tdNodes) == 0) {
                for (var j = 10; j <= 13; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(14, 16, tdNodes) == 0) {
                for (var j = 14; j <= 16; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(17, 19, tdNodes) == 0) {
                for (var j = 17; j <= 19; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(20, 22, tdNodes) == 0) {
                for (var j = 20; j <= 22; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(23, 25, tdNodes) == 0) {
                for (var j = 23; j <= 25; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(26, 28, tdNodes) == 0) {
                for (var j = 26; j <= 28; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(29, 31, tdNodes) == 0) {
                for (var j = 29; j <= 31; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }

            if ($.sumTableBlock(32, 34, tdNodes) == 0) {
                for (var j = 32; j <= 34; j++) {
                    tdNodes[j].className += " blue_bg";
                }
            }
        }
    }

});